import {
    Body,
    Controller,
    Delete,
    Get,
    Param,
    ParseIntPipe,
    Post,
    Put,
    Query,
    UseGuards,
} from '@nestjs/common';

import { MyApi, Roles } from '../modules/action/descriptor/function.descriptoor';
import { MyController } from '../modules/action/descriptor/http.decorator';
import { JwtAuthGuard } from '../modules/auth/guard/jwt-auth.guard';
import { RoleEntity } from '../Entity/role.entity';
import { RoleService } from '../service/role.service';
@UseGuards(JwtAuthGuard)
@MyController('RoleController')
@Controller('role')
export class RoleController {
    constructor(private readonly roleService: RoleService) { }

    @Post()
    @MyApi('添加用户一个用户身份')
    addUser(@Body() roleEntity: RoleEntity) {
        return this.roleService.create(roleEntity);
    }

    @Get()
    @MyApi('查询所有身份信息')  
    @Roles("admin")
    async findAll(): Promise<RoleEntity[]> {
        let role = await this.roleService.findAll();

        return role;
    }

    @Get('rname/:rname')
    @MyApi('查询特定身份信息')
    async findOne(@Param('rname') rname: string) {
        // console.log(rname);
        return this.roleService.findOne(rname);
    }

    @Delete(':id')
    @MyApi('根据id查询删除某个身份信息')
    async deleteById(@Param('id', ParseIntPipe) id: number) {
        return this.roleService.remove(id);
    }

    @Put()
    @MyApi('修改某个身份信息')
    async updateUser(@Body() roleEntity: RoleEntity) {
        return this.roleService.update(roleEntity);
    }
}
